<!DOCTYPE html>

<html>

    <head>

        <meta charset="utf-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <title> - 表单验证 jQuery Validation</title>

        <meta name="keywords" content="">

        <meta name="description" content="">

        <link rel="icon" href="/static/admin/img/logo.png" type="image/x-icon">

        <link rel="shortcut icon" href="favicon.ico"> <link href="/static/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">

        <link href="/static/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">



        <link href="/static/admin/css/style.css?v=4.1.0" rel="stylesheet">

        <link href="/static/admin/css/plugins/datapicker/datepicker3.css" rel="stylesheet">

        <link href="/static/admin/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">



        <link href="/static/admin/css/plugins/summernote/summernote.css" rel="stylesheet">

        <link href="/static/admin/css/upload.css" rel="stylesheet">









        <script src="/static/admin/editor/ueditor.config.js"></script>

        <script src="/static/admin/editor/ueditor.all.js"></script>

        <link href="/static/admin/css/plugins/datapicker/datepicker3.css" rel="stylesheet">

        <link href="/static/admin/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">

        <script src="/static/admin/js/city/jquery-1.11.3.min.js"></script>



        <!-- 全局/static/admin//static/admin//static/admin/js -->

        <script src="/static/admin/js/bootstrap.min.js?v=3.3.6"></script>


        <!--script src="/static/admin/layer/layer.css"></script>-->







        <!--<script src="/static/admin/layer/layer.css"></script>-->

        <script src="/static/admin/layer/layer.js"></script>



        <style>



            .uploadbtn{height:90px;line-height:90px;padding-left:10px;width:90px;border:1px solid #ccc;border-radius: 5px;color: #acacac;z-index: 4;color:#62c8e8}

            .uploadbtn:hover{border:1px solid #aaa;cursor: pointer;}

            .form-control{cursor: pointer;}

            .uploadbtn2{position: absolute;padding: 5px 10px;background: #23b7e5;display:inline-block;border-radius: 5px;color: #ffffff;z-index: 4}

            .uploadbtn2:hover{background: #19a9d5;cursor: pointer;}

            .form-control{cursor: pointer;}
            .nav_yc{width:90%;height:80px;line-height:80px;margin:0px auto}
            .nav_yc ul li{float:left;width:50%;text-align:center;height:35px;line-height:35px;cursor:pointer;color:#fff}
            .clear{clear:both}
            .btn_nav_div2{display:none}
        </style>

        <script>

            //基本设置 下一步
            function Next(){
            var title = $("#title").val();
            var start_time = $("#start_time").val();
            var stop_time = $("#stop_time").val();
            if (title == ''){
            alert('请填写活动名称');
            return false;
            }
            if (start_time == ''){
            alert('设置活动开始时间');
            return false;
            }
            if (stop_time == ''){
            alert('设置活动开始时间');
            return false;
            }
            $(".btn_nav_div1").hide();
            $(".btn_nav_div2").show();
            $(".nav_yc_li2").css("background-color", "#808080");
            $(".nav_yc_li2").css("color", "#fff");
            }
            //活动详情 上一步

            function upper(){
            $(".btn_nav_div1").show();
            $(".btn_nav_div2").hide();
            $(".nav_yc_li2").css("background-color", "#fff");
            }


        </script>


    </head>



    <body class="gray-bg">

        <div class="wrapper wrapper-content animated fadeInRight">

            <div class="row">

                <div class="col-sm-12">

                    <div class="tabs-left">

                        <ul class="nav nav-tabs">

                            <li class="active"><a data-toggle="tab" href="#tab-8" id="add-works">秒杀设置</a> </li>

                        </ul>
                    </div>
                </div>

            </div>



            <div class="ibox-content" id="tab-8">

                <form class="form-horizontal m-t" id="works-form" action="" method="post" onsubmit="return subForm();"  enctype="multipart/form-data" >

                    <input name="id" id="id" value="{if isset($data)}{$data.id}{/if}" type="hidden">


                    <div class="nav_yc">
                        <ul>
                            <li onclick ="upper();" class="nav_yc_li1" style="background-color:#808080">基本设置</li>
                            <li onclick ="Next();"  class="nav_yc_li2" style ='color:#808080'>活动详情</li>
                        </ul>
                        <div class ="clear"></div>
                    </div>

                    <div class="btn_nav_div1">

                        <div class="form-group">

                            <label class="col-sm-1 control-label">活动名称：</label>

                            <div class="col-sm-2">

                                <input id="title" name="title" style="width:300px"  class="form-control" type="text" required=""  value="{if isset($data)}{$data.title}{/if}">

                                <!--  <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请输入公司名称</span>-->

                            </div>

                        </div>
                        
                         <div class="form-group">

                            <label class="col-sm-1 control-label">原  价：</label>

                            <div class="col-sm-2">

                                <input id="y_price" name="y_price" style="width:300px"    class="form-control" type="number" required=""  value="{if isset($data)}{$data.y_price}{/if}">

                            </div>
                    <label class="col-sm-1" style="margin-left:35px;height:40px;line-height:40px">（元）</label>
                        </div>
                        <div class="form-group">

                            <label class="col-sm-1 control-label">秒杀价格：</label>

                            <div class="col-sm-2">

                                <input id="price" name="price" style="width:300px"    class="form-control" type="number" required=""  value="{if isset($data)}{$data.price}{/if}">

                            </div>
                    <label class="col-sm-1" style="margin-left:35px;height:40px;line-height:40px">（元）</label>
                        </div>
                        <div class="form-group">

                            <label class="col-sm-1 control-label">秒杀名额：</label>

                            <div class="col-sm-2">

                                <input id="k_count" name="k_count" style="width:300px"  class="form-control" type="number" required=""  value="{if isset($data)}{$data.k_count}{/if}">

                            </div>
<label class="col-sm-1" style="margin-left:35px;height:40px;line-height:40px">（个）</label>
                        </div>
                        <div class="form-group">

                            <label class="col-sm-1 control-label ">开始时间：</label>

                            <div class="col-sm-3">

                                <input readonly class="form-control" placeholder='请设置开始时间' style="width:300px" id="start_time" required="" name="start_time" value="{if isset($data)}{$data.start_time|date='Y-m-d H:i:s',###}{/if}">

                                <!--<label class="laydate-icon inline demoicon"  onclick="laydate({elem: '#end_time',type: 'datetime'});"></label>-->
                                <!--<label class="laydate-icon inline demoicon"  onclick="laydate({elem: '',type: 'datetime'});"></label>-->

                                <span class="help-block m-b-none" style="width:245px;letter-spacing: 2px;"> </span>

                            </div>

                        </div>
                        <div class="form-group">

                            <label class="col-sm-1 control-label">结束时间：</label>

                            <div class="col-sm-3">

                                <input readonly class="form-control" placeholder='请设置结束时间' style="width:300px" id="stop_time" required="" name="stop_time" value="{if isset($data)}{$data.stop_time|date='Y-m-d  H:i:s',###}{/if}">

                                <!--<label class="laydate-icon inline demoicon" onclick="laydate({elem: '#end_time'});"></label>-->

                                <span class="help-block m-b-none" style="width:245px;letter-spacing: 2px;"></span>

                            </div>

                        </div>
                        <div class="form-group">

                            <label class="col-sm-1 control-label">封面图片：</label>

                            <div class="col-sm-2">

                                <input id="main_img"  class="form-control" type="file" name="main_img" onchange="uploadImg(this, 'imgupload')" style="padding: 0;position: absolute; opacity: 0;z-index: 3 ;cursor: pointer;width:20px;">

                                <p class="uploadbtn" > <span style="font-size:18px">+</span>  上传图片</p>

                                <span  style="margin-left: 120px; margin-top: 5px; width: 200px;" class="help-block m-b-none"></span>

                                <input type="hidden" name="main_img" value="{if isset($data)}{$data.main_img}{/if}" >

                                {if isset($data) && $data.main_img !==''}

                                <img id ="imgupload"  class='willshow' src="{if isset($data)}{$data.main_img}{/if}" style=" display:block;max-height: 200px;margin-top: 32px"/>

                                {else}
                                <img id ="imgupload"  class='willshow' src="" style=" display:none;max-height: 200px;margin-top: 32px"/>
                                {/if}

                            </div>
                        </div>
                        <div class="form-group">

                <label class="col-sm-1 control-label">多图上传：</label>



                <div class="col-sm-3" id="T_upload">



                </div>

            </div>


            <div class="form-group" style="display: none" id="Works_Upload">



            </div>

                        <div class="form-group">

                            <div class="col-sm-8 col-sm-offset-3">

                                <!---->
                                <div class="btn btn-primary btn_nav_yc1"onclick="Next();" >下一步</div>

                            </div>

                        </div>
                    </div>
                    <div class="btn_nav_div2">
                        <div class="form-group">

                            <label class="col-sm-1 control-label">内容：</label>

                            <div class="col-sm-3">

                                <script id="content" name="content" type="text/plain" style="width:1000px;height:300px;">{if isset($data)}{$data.content}{/if}

                                </script>

                                <script type="text/javascript">

                                    var ue = UE.getEditor('content');
                                </script>

                            </div>

                        </div>

                        <div class="form-group" style="display: none" id="Works_Upload">



                        </div>



                        <div class="form-group">

                            <div class="col-sm-8 col-sm-offset-3">
                                <div onclick='upper();' class="btn btn-primary btn_nav_yc2">上一步</div>
                                <button class="btn btn-primary" type="submit" >提交</button>


                            </div>

                        </div>
                    </div>


                </form>

            </div>











            <script src="/static/admin/js/jquery.min.js"></script>


            <script type="text/javascript" src="/static/admin/js/file_images.js"></script>
            <script src="/static/admin/js/jquery-1.7.2.min.js"></script>



            <!-- 自定义js -->



            <script src="/static/admin/js/jquery.min.js?v=2.1.4"></script>

            <script src="/static/admin/js/bootstrap.min.js?v=3.3.6"></script>



            <script src="http://www.jq22.com/jquery/jquery-1.7.1.js"></script>

            <script src="/static/admin/js/T_upload.js"></script>


            <script  type="text/javascript">

                                    $(function () {
                                    $('.uploadbtn').click(function () {
                                    return $('#main_img').click();
                                    });
                                    })
                                            $(function () {

                                            $.Tupload.init({

                                            url: "/admin.php/works/addworksajax",
                                                    title: "图片大小不能超过500kb,为使避免图片上传出现问题，请尽量选择完毕图片后再上传",
                                                    fileNum: 200, // 上传文件数量
                                                    divId: "T_upload", // div  id
                                                    accept: "image/jpeg,image/x-png", // 上传文件的类型
                                                    fileSize: 51200000, // 上传文件的大小
                                                    onSuccess: function (data, i) {
                                                    var temp = eval('(' + data.currentTarget.response + ')');
                                                    if (temp.fileName != undefined) {

                                                    $("#img_src" + i).attr('value', temp.fileName);
                                                    $("#img_src" + i).attr('name', "upload_img");
                                                    var str = '<input type="hidden" name="works_pic[]" value="' + temp.info + '" class="works_pic">';
                                                    $("#Works_Upload").append(str);
                                                    $("#img_src" + i).parent(".uploading-imgBg").siblings("#uploading-tip" + i).children('.onDelPic').attr('idstr', temp.info);
                                                    }

                                                    },
                                                    onDelete: function (i) {

                                                    /*var img_val = $("#img_src"+i).attr("value");
                                                     
                                                     if(img_val != '' && img_val != undefined){
                                                     
                                                     var md = "product";
                                                     
                                                     var img= $.page.getImgUrl(img_val);
                                                     
                                                     $.ajax({
                                                     
                                                     type:"POST",
                                                     
                                                     url: "base/delPic" ,
                                                     
                                                     data : {img:img,id: pid,md:md},
                                                     
                                                     success: function(rel){}
                                                     
                                                     });
                                                     
                                                     }*/

                                                    }

                                            });
                                            })


                                            $(".onDelPic").live('click', function () {

                                    var id = $(this).attr('idstr');
                                    var photo_id = '';
                                    $("#T_upload .photo_id").each(function () {

                                    photo_id = $(this).val();
                                    if (photo_id == id) {

                                    $(this).remove();
                                    }

                                    })

                                            $.ajax({

                                            url: "/admin.php/dynamic/delworksajax",
                                                    type: "post", //get

                                                    data: {id: id},
                                                    dataType: "json",
                                                    success: function (data) {

                                                    },
                                            });
                                    var id_ = $(this).attr("data");
                                    $.Tupload.onDelete(id_, id);
                                    $("#lhezi" + id_).removeClass('show');
                                    });
                                    function uploadImg(file, showImg) {

                                    if (!file.files[0]) {

                                    return false;
                                    }

                                    if (!file.value.match(/.jpg|.gif|.png|.jpeg/i)) {

                                    layer.msg('您选择的图片格式不正确，请重新选择');
                                    return false;
                                    }

                                    if (file.files[0].size > 1 * 1024 * 1024) {

                                    layer.msg('您选择的图片不能大于1M，请重新选择！');
                                    return false;
                                    }

                                    var myPhoto = document.getElementById(showImg);
                                    console.log(myPhoto)

                                            var reader = new FileReader();
                                    //        console.log(reader)

                                    reader.onload = function (e) {

                                    var dataURL = e.target.result;
                                    myPhoto.src = dataURL;
                                    myPhoto.style.display = 'block';
                                    };
                                    reader.readAsDataURL(file.files[0]);
                                    }
                                    function uploadImg2(file, showImg) {

                                    if (!file.files[0]) {

                                    return false;
                                    }

                                    if (!file.value.match(/.jpg|.gif|.png|.jpeg/i)) {

                                    layer.msg('您选择的图片格式不正确，请重新选择');
                                    return false;
                                    }

                                    if (file.files[0].size > 1 * 1024 * 1024) {

                                    layer.msg('您选择的图片不能大于1M，请重新选择！');
                                    return false;
                                    }

                                    var myPhoto2 = document.getElementById(showImg);
                                    var reader = new FileReader();
                                    reader.onload = function (e) {

                                    var dataURL = e.target.result;
                                    myPhoto2.src = dataURL;
                                    myPhoto2.style.display = 'block';
                                    };
                                    reader.readAsDataURL(file.files[0]);
                                    }

                                    window.onload = myfun;
                                    function myfun(){
                                    var imgurls = <?php echo json_encode($imgurl);?>;
                                var urls = eval(imgurls);
                                var str = '';
                                var html = '';
                                var pistr='{$data.works_photo}';
                                if(pistr!=""){
                                            //$('.hezi').addClass('show');
                                            if (urls){
                                    for (var i = 0; i < urls.length; i++) {
                                    $('.hezi').eq(i).addClass('show')
                                            $('#img_src' + i).attr('src', imgurls[i].works_pic);
                                    $('#img_src' + i).parent('.uploading-imgBg').siblings("#uploading-tip" + i).css('display', 'block');
                                    $("#img_src" + i).parent(".uploading-imgBg").siblings("#uploading-tip" + i).children('.onDelPic').attr('idstr', imgurls[i].pic_id);
                                    $("#img_src" + i).parent(".uploading-imgBg").siblings('#uploadTure_' + i).css('display', 'block');
                                    html += '<input type="hidden" name="works_pic[]" value="' + imgurls[i].pic_id + '" class="works_pic">';
                }
                                
                                //$('.hezi').eq(urls.length).addClass('show add')
                                
                                $("#Works_Upload").append(html);
                                
                                    }
                                    
                                }
                            
                            }
                        
                        
                        
                        
</script>



            <script src="/static/admin/laydate/laydate.js"></script>
<script>
                        lay('#version').html('-v' + laydate.v);
                            //执行一个laydate实例
                                laydate.render({
                                    elem: '#start_time' //指定元素
                                            , type: 'datetime' //指定元素
                        });
                        
                    laydate.render({
                                            elem: '#stop_time' //指定元素
                                            , type: 'datetime' //指定元素
            });
            
            function subForm(){
//       files_imgs();
         var formobj = document.getElementById('works-form')

        var formData = new FormData(formobj);
        $.ajax({

            url:"/admin.php/miaosha/addworks",

            data:formData,

            type:"post",

            dataType:'json',

            processData: false,  // 告诉jQuery不要去处理发送的数据

            contentType: false,   // 告诉jQuery不要去设置Content-Type请求头

            success:function(res){

                if(1==res.code) {

                    layer.msg(res.msg);

                    setTimeout(function(){

                        //window.history.go(-1);

                        window.location.href="/admin.php/miaosha/index"

                    },1000);

                }else{

                    layer.msg(res.msg);

                    return false;

                }

            },

            error:function(){

                layer.msg('系统错误');

                return false;

            },



        });

        return false;

    }
            </script>

    </body>





</html>

